<template>
  <!-- 关联项目 -->
  <el-dialog title="项目详情" :visible="value" width="700px" custom-class="dialog-box" @close="onClose" @open="onOpen" :close-on-click-modal="false" :append-to-body="true">
    <el-alert v-if="dataInfo" type="warning">
      <template slot="title">
        <div>报告时间：{{dataInfo.reportTime}}{{dataInfo.reportUnit|changeAssist(reportUnitEnum)}}</div>
        <div>临床意义：{{dataInfo.clinicalApplication}} </div>
      </template>
    </el-alert>
    <br>
    <table v-if="dataInfo" class="table-box">
      <thead>
        <tr>
          <th>项目名称</th>
          <th>英文缩写</th>
          <th>参考值</th>
        </tr>
      </thead>
      <tbody>
        <template v-if="itemList.length>0">
          <tr v-for="(item,index) in itemList" :key="index">
            <td>{{item.name}}</td>
            <td>{{item.englishName}}</td>
            <td>
              <div v-if="item.medicalCheckupReferenceVO">
                <span v-if="item.medicalCheckupReferenceVO.type==1">{{item.medicalCheckupReferenceVO.lowValue}}~{{item.medicalCheckupReferenceVO.highValue}}{{item.medicalCheckupReferenceVO.referenceUnit}}</span>
                <span v-else>{{item.medicalCheckupReferenceVO.referenceValue}}</span>
              </div>
            </td>
          </tr>
        </template>
        <tr v-else>
          <td>{{dataInfo.name}}</td>
          <td>{{dataInfo.englishName}}</td>
          <td>
            <div v-if="dataInfo.medicalCheckupReferenceVO">
              <span v-if="dataInfo.medicalCheckupReferenceVO.type==1">{{dataInfo.medicalCheckupReferenceVO.lowValue}}~{{dataInfo.medicalCheckupReferenceVO.highValue}}{{dataInfo.medicalCheckupReferenceVO.referenceUnit}}</span>
              <span v-else>{{dataInfo.medicalCheckupReferenceVO.referenceValue}}</span>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "curItem"],
  components: {},
  data() {
    return {
      btnLoading: false,
      dataInfo: null,
      reportUnitEnum: [],
      itemList: []
    };
  },
  mounted() {
    const th = this;
    th.getCommonConfigByKey("报告单位").then(res => {
      th.reportUnitEnum = res;
    });
  },
  methods: {
    getData() {
      let th = this;
      let j = {
        id: th.curItem.checkupId
      };
      th.$api.medicalcheckupv2detailid(j).then(res => {
        if (res.executed) {
          res.data.forEach(ele => {
            if (ele.id == th.curItem.checkupId) {
              th.dataInfo = ele;
            } else {
              th.itemList.push(ele);
            }
          });
        }
      });
    },
    onSubmit() {},
    onOpen() {
      let th = this;
      th.getData();
      th.$nextTick(function() {});
    },
    onClose() {
      let th = this;
      th.dataInfo = null;
      th.itemList = [];
      th.$emit("input", false);
    }
  }
};
</script>
